/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package at.tugraz.hidipic.web.propertyeditor;

import at.tugraz.hidipic.model.Project;
import java.beans.PropertyEditorSupport;
import org.apache.log4j.Logger;

/**
 *
 * @author mario
 */
public class ProjectPropertyEditor extends PropertyEditorSupport {

    private final Logger LOG = Logger.getLogger(ProjectPropertyEditor.class);

    @Override
    public void setAsText(String incoming) {
        int projId = -1;
        try {
            projId = Integer.parseInt(incoming);
        } catch (Exception e) {
            LOG.error(e);
        }
        if (projId >= 0) {
            Project project = new Project();
            project.setId(projId);
            setValue(project);
        }
    }

    @Override
    public String getAsText() {
        if ((Project) getValue() != null) {
            int projId = ((Project) getValue()).getId();
            return String.valueOf(projId);
        }
        return null;
    }
}
